home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Apache 1.0 / src / http_log.c < prev    next >
Text File  |  1995-12-04  |  4KB  |  131 lines

  1.  
  2. /* ====================================================================
  3.  * Copyright (c) 1995 The Apache Group.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer. 
  11.  *
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in
  14.  *    the documentation and/or other materials provided with the
  15.  *    distribution.
  16.  *
  17.  * 3. All advertising materials mentioning features or use of this
  18.  *    software must display the following acknowledgment:
  19.  *    "This product includes software developed by the Apache Group
  20.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  21.  *
  22.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  23.  *    endorse or promote products derived from this software without
  24.  *    prior written permission.
  25.  *
  26.  * 5. Redistributions of any form whatsoever must retain the following
  27.  *    acknowledgment:
  28.  *    "This product includes software developed by the Apache Group
  29.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35.  * IT'S CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  43.  * ====================================================================
  44.  *
  45.  * This software consists of voluntary contributions made by many
  46.  * individuals on behalf of the Apache Group and was originally based
  47.  * on public domain software written at the National Center for
  48.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  49.  * For more information on the Apache Group and the Apache HTTP server
  50.  * project, please see <http://www.apache.org/>.
  51.  *
  52.  */
  53.  
  54.  
  55. /*
  56.  * http_log.c: Dealing with the logs and errors
  57.  * 
  58.  * Rob McCool
  59.  * 
  60.  */
  61.  
  62.  
  63. #include "httpd.h"
  64. #include "http_config.h"
  65. #include "http_log.h"
  66.  
  67. void open_error_log(server_rec *s, pool *p)
  68. {
  69.     char *fname;
  70.   
  71.     fname = server_root_relative (p, s->error_fname);
  72.     if(!(s->error_log = pfopen(p, fname, "a"))) {
  73.         fprintf(stderr,"httpd: could not open error log file %s.\n", fname);
  74.         perror("fopen");
  75.         exit(1);
  76.     }
  77. }
  78.  
  79. void open_logs (server_rec *s_main, pool *p)
  80. {
  81.     server_rec *virt, *q;
  82.  
  83.     open_error_log (s_main, p);
  84.  
  85.     for (virt = s_main->next; virt; virt = virt->next) {
  86.     if (virt->error_fname)
  87.     {
  88.         for (q=s_main; q != virt; q = q->next)
  89.         if (q->error_fname != NULL &&
  90.             strcmp(q->error_fname, virt->error_fname) == 0)
  91.             break;
  92.         if (q == virt) open_error_log (virt, p);
  93.         else virt->error_log = q->error_log;
  94.     }
  95.     else
  96.         virt->error_log = s_main->error_log;
  97.     }
  98. }
  99.  
  100. void error_log2stderr(server_rec *s) {
  101.     if(fileno(s->error_log) != STDERR_FILENO)
  102.         dup2(fileno(s->error_log),STDERR_FILENO);
  103. }
  104.  
  105. void log_pid(pool *p, char *pid_fname) {
  106.     FILE *pid_file;
  107.  
  108.     if (!pid_fname) return;
  109.     pid_fname = server_root_relative (p, pid_fname);
  110.     if(!(pid_file = fopen(pid_fname,"w"))) {
  111.     perror("fopen");
  112.         fprintf(stderr,"httpd: could not log pid to file %s\n", pid_fname);
  113.         exit(1);
  114.     }
  115.     fprintf(pid_file,"%ld\n",(long)getpid());
  116.     fclose(pid_file);
  117. }
  118.  
  119. void log_error(char *err, server_rec *s) {
  120.     fprintf(s->error_log, "[%s] %s\n",get_time(),err);
  121.     fflush(s->error_log);
  122. }
  123.  
  124. void log_reason(char *reason, char *file, request_rec *r) {
  125.     fprintf (r->server->error_log,
  126.          "[%s] access to %s failed for %s, reason: %s\n",
  127.          get_time(), file, r->connection->remote_name, reason);
  128.     fflush (r->server->error_log);
  129. }
  130.  
  131.